package service

import (
	"chat_srv/basic/config"
	chat "chat_srv/basic/proto"
	"chat_srv/handler/dao"
	"context"
)

// 关注
func (s *Server) UserFollow(_ context.Context, in *chat.UserFollowReq) (*chat.UserFollowResp, error) {
	// 业务逻辑
	resp, err := dao.UserFollow(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.UserFollowResp{
		Id:      uint64(resp.Id),
		Message: "关注成功",
	}, nil
}

// 取消关注
func (s *Server) UserNotFollow(_ context.Context, in *chat.UserNotFollowReq) (*chat.UserNotFollowResp, error) {
	// 业务逻辑
	resp, err := dao.UserNotFollow(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.UserNotFollowResp{
		Id:      uint64(resp.Id),
		Message: "取消关注成功",
	}, nil
}

// 发送好友申请
func (s *Server) Application(_ context.Context, in *chat.ApplicationReq) (*chat.ApplicationResp, error) {
	// 业务逻辑
	resp, err := dao.Application(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.ApplicationResp{
		Id:      uint64(resp.Id),
		Message: "好友申请已发送",
	}, nil
}

// 同意好友申请
func (s *Server) AcceptApplication(_ context.Context, in *chat.AcceptApplicationReq) (*chat.AcceptApplicationResp, error) {
	// 业务逻辑
	resp, err := dao.AcceptApplication(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.AcceptApplicationResp{
		Id:      uint64(resp.Id),
		Message: "好友申请已同意",
	}, nil
}

// 拒绝好友申请
func (s *Server) RejectApplication(_ context.Context, in *chat.RejectApplicationReq) (*chat.RejectApplicationResp, error) {
	// 业务逻辑
	resp, err := dao.RejectApplication(config.Ctx, in)
	if err != nil {
		return nil, err
	}
	return &chat.RejectApplicationResp{
		Id:      uint64(resp.Id),
		Message: "好友申请已拒绝",
	}, nil
}
